<?php	
class Obj_Articles {
	
	protected static $t;
	
	public static function init() {
		self::$t = new Obj_DBTable_Articles();
	}
	
	public static function getAllArticles($page, $active_only = false) {
		return self::$t->getAllArticles($page, $active_only);
	}
	
	public static function getSitemapArticles() {
		return self::$t->getSitemapArticles();
	}
	
	public static function getNoPagingArticles($activeOnly = false) {
		$ar_ = self::$t->getNoPagingArticles($activeOnly);
		$ar = array();
		foreach ($ar_ as $k => $v) {
			$ar[$v['ID']] = $v;
		}
		return $ar;
	}
		
	public static function saveArticle($arData, $id) {
		if ((int)$id == (int)0) {
			return self::$t->insert($arData);
		}
		else self::$t->update($arData, 'ID = '.intval($id));
		return intval($id);
	}
	
	public static function getOneArticle($id, $activeOnly = false) {
		return self::$t->getOneArticle($id, $activeOnly);
	}
	
	public static function delOneArticle($id){
		return self::$t->delete('ID = '.intval($id));
	}
	
	public static function getAlias($title, $id) {
		$i = 0; 
		$alias = Obj_Text::translit($title);
		$al = $alias; 
		while (self::$t->checkAlias($al, $id)) {
			$al = $alias.'_'.$i++;
		}
		return $al;
	}
	
	
}Obj_Articles::init();

